<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单发货')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-order-delivery" method="post" th:object="${logisticsInfo}">
        <input name="id" type="hidden" th:value="*{id}"/>
        <input name="orderId" type="hidden" th:value="*{orderId}"/>
        <input name="shipperCode" type="hidden" th:value="*{shipperCode}"/>
        <input name="shipperName" type="hidden" th:value="*{shipperName}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>快递公司：</label>
            <div class="col-sm-3">
                <div class="input-group">
                    <input type="text" class="form-control" id="suggest-demo-3" th:value="*{shipperName}" required>
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group" id="inputLogisticsCode">
            <label class="col-sm-3 control-label "><span style="color: red; ">*</span>快递单号：</label>
            <div class="col-sm-3">
                <input class="form-control" type="text" id="logisticsCode" th:field="*{logisticsCode}" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">发货人姓名：</label>
            <div class="col-sm-3">
                <input class="form-control" type="text" name="senderName" id="senderName" th:field="*{senderName}"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label ">发货人联系电话：</label>
            <div class="col-sm-3">
                <input class="form-control" type="text" name="senderPhone" id="senderPhone" th:field="*{senderPhone}"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label ">发货人地址：</label>
            <div class="col-sm-4">
                <input class="form-control" type="text" name="senderAddress" id="senderAddress" th:field="*{senderAddress}"/>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<th:block th:include="include :: bootstrap-suggest-js"/>
<script type="text/javascript">

    if($('input[name="shipperCode"]').val() === "NULL"){
        $('#inputLogisticsCode').hide();
    }else{
        $('#inputLogisticsCode').show();
    }

    //选择快递公司信息
    $("#suggest-demo-3").bsSuggest({
        indexId: 1,
        indexKey: 0,
        keyField: "company",
        hideOnSelect: true,
        emptyTip:'<b>没有找到快递公司信息</b>',
        effectiveFields: ["id", "company", "expCode", "expPhone"],
        effectiveFieldsAlias: {
            id: "ID",
            company: "快递公司名称",
            expCode: "快递公司编号",
            expPhone: "快递公司电话",
        },
        data: {
            'value': (function () {
                var list = '';    // 先定义个值，方便下面赋值
                $.ajax({
                    type: 'get',
                    url: ctx+"back/order/searchLogisticsCompanyList",
                    dataType: 'json',
                    async: false,
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            list = result.data;
                        } else {
                            $.modal.alert(result.msg);
                        }
                    }
                });
                return list;
            })()
        }
    }).on('onSetSelectValue', function (e, keyword, data) {
        if(data.expCode === "NULL" || data.expCode === "NULL2"){
            $('#inputLogisticsCode').hide();
        }else{
            $('#inputLogisticsCode').show();
        }
        $('input[name="shipperName"]').val(data.company);
        $('input[name="shipperCode"]').val(data.expCode);
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(ctx + "back/order/delivery", $('#form-order-delivery').serialize());
        }
    }
</script>
</body>
</html>
